﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MyWindowsService
{
    public class Util
    {
        private static System.Data.IDbConnection myDBConnection = null;
        /// <summary>
        /// 获得数据库连接对象
        /// </summary>
        public static System.Data.IDbConnection DBConnection
        {
            get
            {
                if (myDBConnection == null)
                {
                    myDBConnection = new System.Data.OleDb.OleDbConnection(
                        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\""
                        + System.IO.Path.Combine(
                        System.Windows.Forms.Application.StartupPath,
                        "FileSystemWatcher.mdb") + "\"");
                    myDBConnection.Open();
                }
                return myDBConnection;
            }
        }
        /// <summary>
        /// 关闭数据库连接
        /// </summary>
        public static void CloseDBConnection()
        {
            if (myDBConnection != null)
            {
                myDBConnection.Close();
                myDBConnection = null;
            }
        }
    }
}
